<template>
  <div class="newVs">
    <div class="mask"></div>
    <div class="new_vs">
      <!-- 头部结构 -->
      <div class="title">
        <span>{{ title }}资料</span>
        <i class="el-icon-close" @click="iconCloseClick"></i>
      </div>
      <div class="middle_box">
        <!-- 条码建档(品牌公司) -->
        <div class="tiao_ma_jian_dang">
          <div class="tiao_ma_title">
            <span class="new">条码建档(品牌公司)</span>
            <i class="el-icon-question left_8px" @click="OIclick"></i>
          </div>
          <div class="tiaoma_box">
            <span class="contener2 right_8px">条码规律(品牌公司)</span>
            <el-input
              v-model="pin_pai_inputvalue"
              :disabled="title === '编辑' ? true : false"
            ></el-input>
            <!-- 后端要求改输入框 -->
            <!-- <el-select v-model="pin_pai_pullSelectValue" placeholder="请选择">
              <el-option
                v-for="item in pin_pai_pullSelectList"
                :key="item.id"
                :label="item.company"
                :value="item.company"
              >
              </el-option>
            </el-select> -->
            <i class="el-icon-question left_8px" @click="OIclick"></i>
            <span style="margin-left: 90px" class="right_8px">尺寸种类</span>
            <el-select v-model="sizeKindPullSelectValue" placeholder="请选择">
              <el-option
                v-for="item in sizeKindPullSelectList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
            <i class="el-icon-question left_8px" @click="OIclick"></i>
          </div>
        </div>
        <div class="table_left_content">
          <div>
            <!-- 
          条码位数
         -->
            <div class="tiaoma_weishu">
              <div class="tiao_ma_title">
                <span class="new">条码位数</span>
                <i class="el-icon-question left_8px" @click="OIclick"></i>
                <div class="weishu_box">
                  <span class="right_8px">款号</span>
                  <el-input
                    v-model.number="styleNumberInputValue"
                    type="number"
                    clearable
                    @input="styleNumberInputChange"
                  >
                  </el-input>
                  <span class="right_8px left_8px">色号/尺寸</span>
                  <el-input v-model="colorSizeInputvalue" clearable> </el-input>
                  <span class="right_8px left_8px">验证码</span>
                  <el-input v-model="codeInputValue" clearable> </el-input>
                </div>
                <!--  参考条码样式-->
                <div class="cankao">
                  <span class="right_8px">参考条码样式</span>
                  <el-input
                    v-model="refCodeStyleInputvalue"
                    clearable
                  ></el-input>
                </div>
              </div>
            </div>
            <!-- 分隔开关 -->
            <div class="fenge_kaiguan">
              <div class="fenge_kaiguan_title">
                <span class="new">分隔开关</span>
                <i class="el-icon-question left_8px" @click="OIclick"></i>
              </div>
              <!--  -->
              <div class="foot_contener1">
                <p class="contener5 right_8px">款号与颜色之间是否有"——"</p>
                <!--款号 改为款号-->
                <el-switch
                  v-model="styleNumer_and_color_switch"
                  active-color="#017aff"
                ></el-switch>
                <p class="contener6 right_8px">是否为款号、尺码、颜色</p>
                <el-switch
                  v-model="styleNumberSizeColorSwitch"
                  active-color="#017aff"
                ></el-switch>
              </div>
              <div class="foot_contener1">
                <p class="contener5 right_8px">色号与尺码之间是否有"——"</p>
                <!--款号 改为款号-->
                <el-switch
                  v-model="color_and_size_switch"
                  active-color="#017aff"
                ></el-switch>
                <p class="contener6" style="margin-right: 40px">
                  条码与货号是否一致
                </p>
                <el-switch
                  v-model="barCode_and_articleNumber_switch"
                  active-color="#017aff"
                ></el-switch>
              </div>
              <!--  -->
              <div class="foot_contener3">
                <span class="contener5">末尾为售价 售价隔开符</span>
                <el-input v-model="separativeSignInputValue"></el-input>
              </div>
              <!-- 底部说明 -->
              <div class="explain">
                <i class="el-icon-question" @click="OIclick"></i>
                <span>说明：</span>
                <span
                  style="display: inline; color: #017aff; cursor: pointer"
                  @click="OIclick"
                >
                  条码与货号的区别，与操作说明
                </span>
              </div>
            </div>
          </div>
          <!-- 表格 -->
          <div class="table_component_container">
            <!-- 表格组件 -->
            <SizeLIst :sizeKindId="sizeKindPullSelectValue" :title="title" />
          </div>
        </div>
        <!-- 关闭按钮 -->
        <div class="buttom_btn_container">
          <el-button class="f_button" @click="iconCloseClick">关闭</el-button>
          <el-button class="f_button1" type="primary" @click="keepBtnClick"
            >保存</el-button
          >
        </div>
      </div>
    </div>
    <!-- 说明组件 -->
    <Oling v-if="isShowOling" @closeOI="closeOI" />
  </div>
</template>
<script>
// 接口
import {
  get_pin_pai_gongsi_data_api,
  getSizeType_data_api,
  add_bar_code_rule_api,
  edit_bar_code_rule_api
} from '../../../../request/baseInfo/barcode_file_request.js'
// 说明组件
import Oling from '../../VendorDoc/childComps/OIimg.vue'
// 尺码组件
import SizeLIst from '../../VendorDoc/childComps/SizeList.vue'
export default {
  components: {
    Oling,
    SizeLIst
  },
  props: {
    currentTableRowDbObj: {
      type: Object,
      default() {
        return {}
      }
    },
    title: {
      type: String,
      default: '新建'
    }
  },
  data() {
    return {
      //
      isShowOling: false,
      // 品牌公司输入的值
      pin_pai_inputvalue: '',
      // 品牌公司和数组
      pin_pai_pullSelectValue: '',
      pin_pai_pullSelectList: [],
      // 尺码种类和数组（选中的就是一个number类型）
      sizeKindPullSelectValue: '',
      sizeKindPullSelectList: [],
      // 款号输入的值
      styleNumberInputValue: '',
      // 色号/尺寸输入的值
      colorSizeInputvalue: '',
      //验证码输入的值
      codeInputValue: '',
      //参考条码样式输入的值
      refCodeStyleInputvalue: '',
      //款号与颜色之间是否有"——"
      styleNumer_and_color_switch: true,
      //是否为款号、尺码、颜色
      styleNumberSizeColorSwitch: false,
      //色号与尺码之间是否有"——"
      color_and_size_switch: false,
      //条码与货号是否一致
      barCode_and_articleNumber_switch: true,
      //末尾为售价 售价隔开符
      separativeSignInputValue: '/'
    }
  },
  created() {
    this.get_pin_pai_gongsi_data()
    this.getSizeType_data()
    this.showEditIfno()
  },
  methods: {
    // 款号输入框输入的时候，触发的函数
    styleNumberInputChange(val) {
      // 变大写
      this.styleNumberInputValue = val.toUpperCase()
    },
    // 如果是点击编辑进来的，那么就直接拿到数据来展示
    showEditIfno() {
      if (this.title !== '编辑') return
      // 下面一系列的赋值，都是编辑展示
      this.pin_pai_inputvalue = this.currentTableRowDbObj.company
      this.sizeKindPullSelectValue = this.currentTableRowDbObj.sizeKindId
      this.styleNumberInputValue = this.currentTableRowDbObj.styleNumber
      this.colorSizeInputvalue = this.currentTableRowDbObj.colorNumber
      this.codeInputValue = this.currentTableRowDbObj.code
      this.refCodeStyleInputvalue = this.currentTableRowDbObj.reference
      this.styleNumer_and_color_switch =
        this.currentTableRowDbObj.styleColor === 1 ? true : false
      this.styleNumberSizeColorSwitch =
        this.currentTableRowDbObj.styleColorSize === 1 ? true : false
      this.color_and_size_switch =
        this.currentTableRowDbObj.colorSize === 1 ? true : false
      this.barCode_and_articleNumber_switch =
        this.currentTableRowDbObj.barCodeArticleNumberEqual === 1 ? true : false
      this.separativeSignInputValue = this.currentTableRowDbObj.partitionPrice
    },
    // 点击保存
    async keepBtnClick() {
      // console.log(parseInt(this.styleNumberInputValue))
      // return
      // 后端要的参数
      const paramsObj = {
        barCodeArticleNumberEqual: this.barCode_and_articleNumber_switch
          ? 1
          : 0,
        code: parseInt(this.codeInputValue),
        colorNumber: parseInt(this.colorSizeInputvalue),
        company: this.pin_pai_inputvalue,
        partitionPrice: this.separativeSignInputValue,
        reference: this.refCodeStyleInputvalue,
        sizeKindId: parseInt(this.sizeKindPullSelectValue),
        styleColor: this.styleNumer_and_color_switch ? 1 : 0,
        styleColorSize: this.styleNumberSizeColorSwitch ? 1 : 0,
        // 这个是款号位数
        styleNumber: parseInt(this.styleNumberInputValue),
        colorSize: this.color_and_size_switch ? 1 : 0
      }
      console.log(paramsObj, 'paramsObj')
      if (this.title === '编辑') {
        paramsObj.id = this.currentTableRowDbObj.id
        const { data: res } = await edit_bar_code_rule_api(paramsObj)
        console.log(res, '编辑接口')
        if (res.code !== 200) return
        this.$message.success('保存成功')
        // 刷新父组件的数据
        this.$emit('get_pin_pai_gongsi_data')
        return
      }
      const { data: res } = await add_bar_code_rule_api(paramsObj)
      console.log(res, '新增接口')
      if (res.code === 200) {
        this.$message.success('保存成功')
        // 刷新父组件的数据
        this.$emit('get_pin_pai_gongsi_data')
      }
    },
    iconCloseClick() {
      this.$emit('closeBarcodeFile')
    },
    // 问号icon被点击
    OIclick() {
      this.isShowOling = true
    },
    // 监听子组件的closeIcon关闭被点击的时候，触发的函数
    closeOI() {
      this.isShowOling = false
    },
    // 获取条码规律品牌公司
    async get_pin_pai_gongsi_data() {
      const { data: res } = await get_pin_pai_gongsi_data_api()
      console.log(res, '获取条码规律品牌公司')
      this.pin_pai_pullSelectList = res.data
    },
    // 获取尺码种类
    async getSizeType_data() {
      const { data: res } = await getSizeType_data_api()
      console.log(res, '获取尺码种类')
      // 返回的是数组，数组中的每一项时一个number类型，然后弄成对象
      res.data.forEach((item) => {
        this.sizeKindPullSelectList.push({ label: item, value: item })
      })
    }
  }
}
</script>
<style lang="less" scoped>
/* 新建资料 */
.mask {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  opacity: 0.3;
  z-index: 9;
}
// 这里的层级要比这个还低
.new_vs {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: 1000px;
  max-height: 800px;
  z-index: 10;
  background-color: white;
  overflow: auto;
}
// 下面是一个下拉框的样式
/deep/.el-select {
  // 宽已经生效
  width: 160px;
  height: 32px;
  .el-input--suffix {
    width: 160px;

    height: 32px;
    .el-input__inner {
      width: 160px;

      height: 32px;
    }
    .el-input__icon {
      line-height: unset;
    }
  }
}
//输入框的样式
// input输入框的样式
/deep/.el-input {
  //icon样式
  .el-input__icon {
    line-height: 34px;
  }
  // 宽度生效
  width: 150px;
  height: 32px;
  .el-input__inner {
    height: 32px;
  }
}
/* 
  头部样式
*/
.title {
  width: 100%;
  height: 48px;
  background: #f8f8f8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  span {
    font-weight: 800;
  }
  i {
    cursor: pointer;
    font-weight: 800;
  }
}
.el-icon-question:before {
  color: #017aff;
  // position: relative;
  // left: 10px;
  // top: 11px;
}
//
.middle_box {
  padding: 0 10px;
}
//
.tiao_ma_jian_dang {
  .tiao_ma_title {
    margin: 10px 0;
    .new {
      font-weight: bold;
      color: #222222;
    }
  }
}
.tiaoma_weishu {
  .tiao_ma_title {
    // margin: 10px 0;
    .new {
      font-weight: bold;
      color: #222222;
    }
  }
}
.weishu_box {
  margin: 10px 0;
}
.fenge_kaiguan {
  .fenge_kaiguan_title {
    margin: 10px 0;
    .new {
      font-weight: bold;
      color: #222222;
    }
  }
}
.foot_contener1 {
  display: flex;
  align-items: center;
  margin: 10px 0;
  .contener6 {
    margin-left: 100px;
  }
}
.foot_contener3 {
  // input输入框的样式
  /deep/.el-input {
    //icon样式
    .el-input__icon {
      line-height: 30px;
    }
    // 宽度生效
    width: 40px;
    height: 30px;
    .el-input__inner {
      height: 30px;
    }
  }
}
.explain {
  margin: 20px 0;
}
.buttom_btn_container {
  display: flex;
  justify-content: flex-end;
  margin: 10px 0;
}
.left_8px {
  margin-left: 8px;
}
.right_8px {
  margin-right: 8px;
}
.table_left_content {
  display: flex;
  margin: 20px 0;
}
.table_component_container {
  margin-left: 20px;
}
</style>
